//
//  PaperIntroduceViewCell.m
//  ForestPack
//
//  Created by 骆锴 on 2018/7/24.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "PaperIntroduceViewCell.h"
#import "PaperBoxDetialModel.h"

@interface PaperIntroduceViewCell()

@property (nonatomic,strong)  UILabel   * introduce;
@property (nonatomic,strong)  UILabel   * price;
@property (nonatomic,strong)  UIView    * baseView1;
@property (nonatomic,strong)  UIView    * baseView2;
@property (nonatomic,strong)  UILabel   * price1;
@property (nonatomic,strong)  UILabel   * price2;
@property (nonatomic,strong)  UILabel   * price3;

@property (nonatomic,strong)  UILabel   * amount1;
@property (nonatomic,strong)  UILabel   * amount2;
@property (nonatomic,strong)  UILabel   * amount3;

@property (nonatomic,strong)  NSMutableArray *pricevalue;
@property (nonatomic,strong)  NSMutableArray *numvalue;

@end

@implementation PaperIntroduceViewCell

+ (PaperIntroduceViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"PaperIntroduceCell";
    PaperIntroduceViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[PaperIntroduceViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell createSubView];
    }
    
    return cell;
}

-(void)createSubView{
    self.introduce =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(10), SCREEN_WIDTH, ScreenX375(30.5))];
    self.introduce.font = Kfont(12);
    self.introduce.numberOfLines = 2;
    self.introduce.textColor = REXADECIMALCOLOR(@"#999999");
    self.introduce.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.introduce];
    
    self.price =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(55), ScreenX375(100), ScreenX375(14.5))];
    self.price.text = @"￥15-45";
    self.price.font = Kfont(18);
    self.price.textColor = ThemeColor;
    self.price.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.price];
    
    UILabel *explanation =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(57.5), ScreenX375(50), ScreenX375(12))];
    explanation.text = @"价格说明";
    explanation.font = Kfont(12);
    explanation.textColor = REXADECIMALCOLOR(@"#ff9500");
    explanation.textAlignment = NSTextAlignmentLeft;
    [self addSubview:explanation];
    
    _baseView1 = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(84.5), SCREEN_WIDTH, ScreenX375(62))];
    _baseView1.backgroundColor = REXADECIMALCOLOR(@"#fff4e4");
    [self addSubview:_baseView1];
    
    _baseView2 = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(84.5), SCREEN_WIDTH, ScreenX375(62))];
    _baseView2.backgroundColor = REXADECIMALCOLOR(@"#fff4e4");
    [self addSubview:_baseView2];
    
    UILabel *pricetitle =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(13), ScreenX375(38), ScreenX375(14))];
    pricetitle.text = @"价格";
    pricetitle.font = Kfont(14);
    pricetitle.textColor = REXADECIMALCOLOR(@"#333333");
    pricetitle.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:pricetitle];
    
    UILabel *numtitle =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(36), ScreenX375(38), ScreenX375(14))];
    numtitle.text = @"数量";
    numtitle.font = Kfont(14);
    numtitle.textColor = REXADECIMALCOLOR(@"#333333");
    numtitle.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:numtitle];
    
    _price1 =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(83), ScreenX375(14), ScreenX375(50), ScreenX375(12))];
    _price1.font = Kfont(14);
    _price1.textColor = REXADECIMALCOLOR(@"#ff9500");
    _price1.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:_price1];
    
    _amount1 =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(83), ScreenX375(37.5), ScreenX375(80), ScreenX375(12))];;
    _amount1.font = Kfont(14);
    _amount1.textColor = REXADECIMALCOLOR(@"#333333");
    _amount1.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:_amount1];
    
    _price2 =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(176.5), ScreenX375(14), ScreenX375(50), ScreenX375(12))];
    _price2.font = Kfont(14);
    _price2.textColor = REXADECIMALCOLOR(@"#ff9500");
    _price2.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:_price2];
    
    _amount2 =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(176.5), ScreenX375(37.5), ScreenX375(80), ScreenX375(12))];;
    _amount2.font = Kfont(14);
    _amount2.textColor = REXADECIMALCOLOR(@"#333333");
    _amount2.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:_amount2];
    
    _price3 =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(285), ScreenX375(14), ScreenX375(50), ScreenX375(12))];
    _price3.font = Kfont(14);
    _price3.textColor = REXADECIMALCOLOR(@"#ff9500");
    _price3.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:_price3];
    
    _amount3 =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(285), ScreenX375(37.5), ScreenX375(80), ScreenX375(12))];;
    _amount3.font = Kfont(14);
    _amount3.textColor = REXADECIMALCOLOR(@"#333333");
    _amount3.textAlignment = NSTextAlignmentLeft;
    [_baseView1 addSubview:_amount3];

    [self addSubview:_baseView1];
}

-(void)initWithModel:(PaperBoxDetialModel *)model{
    _baseView2.hidden = YES;
    
    NSMutableArray *priceArray = [NSMutableArray array];
    NSMutableArray *amountArray = [NSMutableArray array];
    for (NSDictionary *dict in model.price_example) {
        CGFloat  price = [[dict valueForKey:@"price"] doubleValue];
        [priceArray addObject:@(price)];
        CGFloat  amount = [[dict valueForKey:@"amount"] doubleValue];
        [amountArray addObject:@(amount)];
    }
    _introduce.text = model.goods_des;
    if (priceArray.count >0 && amountArray.count >0) {
        _price1.text = [NSString stringWithFormat:@"￥%@",priceArray[0]];
        _price2.text = [NSString stringWithFormat:@"￥%@",priceArray[1]];
        _price3.text = [NSString stringWithFormat:@"￥%@",priceArray[2]];
        _amount1.text = [NSString stringWithFormat:@"%@个",amountArray[0]];
        _amount2.text = [NSString stringWithFormat:@"%@个",amountArray[1]];
        _amount3.text = [NSString stringWithFormat:@"%@个",amountArray[2]];
        NSString *pricevalue = [NSString stringWithFormat:@"￥%@-%@",model.min_price,model.goods_price];
        _price.text = pricevalue;
    }
   
}

-(void)initWithPackagingModel:(PackagingExcipientModel *)model{
    _introduce.text = model.goods_des;
    _price.text = [NSString stringWithFormat:@"￥%@",model.price];
    _baseView1.hidden = YES;
    
    NSMutableArray *title = [NSMutableArray array];
    [title addObject:@"浏览量"];
    [title addObject:@"收藏量"];
    [title addObject:@"销量"];
    [title addObject:@"库存量"];
    
    NSMutableArray *content = [NSMutableArray array];
    [content addObject:model.see_num];
    [content addObject:model.collection];
    [content addObject:model.volume];
    [content addObject:model.store];
    
    for (int i = 0;i < title.count; i++) {
        UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake( i * SCREEN_WIDTH/4, ScreenX375(14), SCREEN_WIDTH/4, ScreenX375(14))];
        titleLable.text = [title objectAtIndex:i];
        titleLable.font = Kfont(14);
        titleLable.textColor = REXADECIMALCOLOR(@"#ff9500");
        titleLable.textAlignment = NSTextAlignmentCenter;
        [_baseView2 addSubview:titleLable];
        
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake( i * SCREEN_WIDTH/4, ScreenX375(38), SCREEN_WIDTH/4, ScreenX375(14))];
        if (i < 2) {
            contentLabel.text = [NSString stringWithFormat:@"%@次",[content objectAtIndex:i]];
        }else{
            contentLabel.text = [NSString stringWithFormat:@"%@个",[content objectAtIndex:i]];
        }        
        contentLabel.font = Kfont(14);
        contentLabel.textColor = REXADECIMALCOLOR(@"#333333");
        contentLabel.textAlignment = NSTextAlignmentCenter;
        [_baseView2 addSubview:contentLabel];
    }
}

@end
